package cn.francis.chatplatform.modules.message.service.impl;


import cn.francis.ai.api.AIChatService;
import cn.francis.chatplatform.modules.message.service.ChatMessageService;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class ChatMessageServiceImpl implements ChatMessageService{

    private final AIChatService chatService;
    @Override
    public String communicate(Long sessionId, String question) {
        String chat = chatService.chat(question);
        JSONObject entries = JSONUtil.parseObj(chat);
        String content = entries.getJSONArray("choices")
                .getJSONObject(0)
                .getJSONObject("message")
                .getStr("content");
        log.info(content);
        return content;
    }
}




